package com.matrix.draft.jvm.lianjie;

/**
 * 测试内部类线程安全的单例
 */
public class Singleton {
    private Singleton(){

    }

    // 内部类,由ClassLoader保证线程安全
    private static class Inner{
        private static final Singleton INSTANCE = new Singleton() ;
        static {
            System.out.println("Inner cinit");
        }
    }

    // 获取实例
    public static Singleton getInstance(){
        return Inner.INSTANCE;
    }
}